<template lang="wxml">
	<view class="home">
<view  class="contaion">
        <search @click='getclick'></search>


</view>
		

		<!-- 轮播图 -->
		<swiper class="swiper"  :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<navigator :url="'../goods_detail/goods_detail?goods_id=' + item.goods_id"  >
					<image :src="item.image_src" />
				</navigator>
			</swiper-item>
		</swiper>


		<!-- 导航区 -->
		<view class="nav" >
			<navigator  v-for="(item, index) in navList" :key="index"  @click="navClickHandler(item)">
				<image :src="item.image_src" />
			</navigator>
			
		</view>


		<!-- 楼层数据 -->
		<view class="floors" v-for="(item, index) in floorList" :key="index">
			<view class="floor">
				<view class="title">
					<image :src="item.floor_title.image_src" />
				</view>
		<view class="floor-img-box">
  <!-- 左侧大图片的盒子 -->
  <navigator class="left-img-box" :url="item.product_list[0].url">
    <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
  </navigator>
  <!-- 右侧 4 个小图片的盒子 -->
  <view class="right-img-box">
    <navigator class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="item2.url">
      <image :src="item2.image_src" mode="widthFix" :style="{width: item2.image_width + 'rpx'}"></image>
    </navigator>
  </view>
</view>
			</view>
		</view>
	</view>
</template>

<script>
// 导入自己封装的 mixin 模块
import badgeMix from '@/mixins/tabbar-badge.js'
// 1.导入
import search from '@/components/search'
export default {
  mixins:[badgeMix],
  data() {
    return {
      //  轮播图的数据列表，默认为空数组
      swiperList: [],
      // 分类导航的数据列表
      navList: [],
      // floor楼层的数据
      floorList: []
    }
  },
  // 2.注册
  components: {
    search: search
  },
  onLoad() {
    //  在小程序页面刚加载的时候，调用的方法
    this.getSwiperList()
    this.getNavList()
    this.getfloorList()
  },
  methods: {
    // 获取轮播图数据
    async getSwiperList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
      // console.log(res)
      this.swiperList = res.message
    },
    // 获取分类导航数据
    async getNavList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/catitems')
      // console.log(res)
      this.navList = res.message
    },
    // nav-item 项被点击时候的事件处理函数
    navClickHandler(item) {
      // 判断点击的是哪个 nav
      if (item.name === '分类') {
        uni.switchTab({
          url: '../category/index'
        })
      }
    },
    // 获取楼层数据
    async getfloorList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/floordata')
      // 通过双层 forEach 循环，处理 URL 地址
      res.message.forEach(floorList => {
        floorList.product_list.forEach(prod => {
          prod.url = '/src/pages/good_list/good_list' + prod.navigator_url.split('?')[1]
        })
      })
      this.floorList = res.message
    },
    // 跳转到搜索页面
    getclick() {
      console.log(11)
      uni.navigateTo({
        url: '../searchList/searchList'
      })
    }
  }
}
</script>

<style lang="less">
.swiper {
  height: 340rpx;
  image {
    width: 750rpx;
    height: 340rpx;
  }
}

.nav {
  display: flex;
  navigator {
    flex: 1;
    text-align: center;
    image {
      width: 128rpx;
      height: 140rpx;
      margin: 20rpx 0;
    }
  }
}

.floors {
  // 公共楼层
  .floor {
    .title {
      box-sizing: border-box;
      padding-top: 20rpx;
      padding-left: 16rpx;
      background-color: #f4f4f4;
      image {
        width: 100%;
        height: 60rpx;
      }
    }
    .imgs {
      padding: 20rpx 12rpx;
      overflow: hidden;
      .item {
        float: left;
        margin-right: 10rpx;
        margin-bottom: 10rpx;
      }
      .item image {
        width: 100%;
        height: 100%;
      }
      .item:nth-child(1) {
        width: 232rpx;
        height: 386rpx;
      }
      .item:nth-child(2),
      .item:nth-child(5) {
        width: 273rpx;
        height: 188rpx;
      }
      .item:nth-child(3),
      .item:nth-child(4) {
        width: 203rpx;
        height: 188rpx;
      }
      // 3 5 没有右侧margin
      .item:nth-child(3),
      .item:nth-child(5) {
        margin-right: 0;
      }
    }
  }

  // 第一楼层：less嵌套结构，在下面覆盖上面样式的话，注意嵌套结构一样；
  .floor:nth-child(1) {
    .imgs {
      // n:0; 2 3 4 5
      .item:nth-child(n + 2) {
        width: 236rpx;
        height: 188rpx;
      }
    }
  }
}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.floor-img-box {
  display: flex;
  padding-left: 10rpx;
}
.contaion {
  // 设置定位效果为“吸顶”
  position: sticky;
  // 吸顶的“位置”
  top: 0;
  // 提高层级，防止被轮播图覆盖
  z-index: 999;
}
</style>
